import React from 'react';
import { Alert } from 'antd';
import { IAsyncState } from 'hooklib/async';
const style = {
  display: 'inline-block',
};

interface IProps {
  as: IAsyncState;
}

export default function TaskState({ as }: IProps) {
  let sts, type: "info" | "success" | "error" | undefined;
  if (as.p) {
    sts = '进行中..';
    type = 'info';
  } else if (as.o) {
    sts = '成功执行';
    type = 'success';
  } else if (as.e) {
    sts = String(as.e);
    type = 'error';
  } else {
    type = 'info';
  }
  const msg = as.u + ' ' + sts;
  return <Alert type={type} message={msg} style={style} />;
}
